<template>
	<view style="background: #fff;">
		<view class="top">
            <view class="box">
				<view class="box_left">
					<text>标题</text>
				</view>
				<view class="box_text">
					<input placeholder="请输入标题" v-model="title"/>
				</view>
			</view>
			<view class="top_left">
				<textarea class="sr" placeholder="请输入内容..." v-model="content" maxlength="800"></textarea>
			</view>
			<view class="bom">
				<view class="bom_img">
					<view class="item" v-for="(item,index) in fileList" :key="index">
						<image :src="item" mode="aspectFill"></image>
						<u-icon class="icon" name="close-circle-fill" @click="delImg(index)"></u-icon>
					</view>
					<view class="item" v-if="fileList.length < 6"  @tap="chooseVideoImage">
						<view class="item_icon">
							<u-icon name="plus"></u-icon>
						</view>
						<view class="item_text">选择图片</view>
					</view>
				</view>
			</view>
		</view>
        <view class="btn" @click="issue">发布任务</view>
		<u-popup v-model="is_tishiDetail" width="80%" class="popup" mode="center" border-radius="20">
			<view class="dz_box">
				<view class="dz_close"  @click="set_tishi()"><image src="../../static/close.png"></image></view>
				<view class="dz_title">Tips:</view>
				<view class="dz_content">
					<view><view class="hong"></view> 只接受无偿赠送，非二手交易</view>
					<view style="margin-top: 10rpx;"><view class="hong"></view> 你送出的闲置运费由领取者承担</view>
					<view style="margin-top: 10rpx;margin-bottom: 60rpx;"><view class="hong"></view> 感谢你为节能环保做出的努力</view>
				</view>
			</view>
		</u-popup>	
	</view>
</template>
<script>
	

	export default {
		data() {
			return {
				index:'',
                fileList:[],
				title:'',
				id:0,
				content:'',
				is_tishiDetail:false,
				is_fb:false,
			}
		},
		onLoad(p) {
			//判断是否是华为
			let isHuaWei= getApp().globalData.isHuaWei;
			if(isHuaWei){
				this.setData({
					isHuaWei: isHuaWei
				})
			}
			this.userInfo = uni.getStorageSync('userInfo'); 

			if(p.id){
				this.id = p.id;
				this.getDetail();
			}

		},
		onShow() {
			
		},
		methods: {
			getDetail:function(){
				uni.request({
                	url: 'https://oa.yuxiang123.cn/api/distribute_task/getInfo',
					header: {
						"content-type": "application/x-www-form-urlencoded"
					},
					method: 'POST',
					data:{
						token:uni.getStorageSync('token'),
						id:this.id,
						type:1
					},
					success: (res) => {
						if(res.data.code == 1){
							this.title = res.data.data.title;
							this.content = res.data.data.content;
							this.fileList = res.data.data.imgs_arr;
						}
					}
				})
			},
			//点击上传图片或视频
			chooseVideoImage() {
				var that = this;
                if(!uni.getStorageSync('get_image_issueDetail') && that.isHuaWei){
                    uni.showModal({
                        title: "获取你的相册/相机权限",
                        content: "将获取你的相册/相机权限,用于发布任务",
                        success: function (res) {
                            if (res.cancel) {
                            } else if (res.confirm) {
                                uni.setStorageSync('get_image_issueDetail',1);
                                that.selectImg(9);
                            }
                        },
                    });
                }else{
                    that.selectImg(9);
                }
			},
			issue(){
				if(this.title == ''){
					return this.$Toast('请输入标题!')
				}
                if(this.content == ''){
					return this.$Toast('请输入内容!')
				}
				if(this.fileList == []){
					return this.$Toast('请选择图!')
				}
				var imgStr = '';
				for(var i=0;i<this.fileList.length;i++){
					if(i+1==this.fileList.length){
						imgStr += this.fileList[i]
					}else{
						imgStr += this.fileList[i] + ','
					}
				}
				if(this.is_fb){
					this.$Toast('请勿重复点击发布');
					return false;
				}
				this.is_fb = true;
				var that = this;
				//发布之前验证图片和视频和文字是否违规
				uni.request({
					url: 'https://oa.yuxiang123.cn/api/shop/shop_add_task',
					header:{"content-type": "application/x-www-form-urlencoded"},
					data:{
						title:this.title,
						content:this.content,
						imgs:imgStr,
                        token:uni.getStorageSync('token'),
						id:this.id
					},
					method: 'POST',
					success: (res) => {
                        setTimeout(function () {
                            that.is_fb = false;
                        }, 1000);
                        this.$Toast(res.data.msg)
					}
				})
			},
			setnotice(){
				uni.request({
					url:'https://oa.yuxiang123.cn/api/order/product_notice',
					method:'POST',
					header:{"content-type":"application/x-www-form-urlencoded"},
					data:{'product_id':this.product_id,token:uni.getStorageSync('token'),'notice':this.on},
				})
			},
			selectImg(index){
				var that = this;
				// #ifdef  APP-PLUS
				uni.chooseImage({
						count: 9, //默认9
						sizeType: ['original'],
						crop:{
							width:300,
							height:400
						},
						success: function (res) {
                            for (let index = 0; index < res.tempFilePaths.length; index++) {
                                that.upImg(res.tempFilePaths[index],'index')
                            }
						},
				});
 				// #endif
				// #ifdef MP-WEIXIN
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original'],
					success: function (res) {
                        for (let index = 0; index < res.tempFilePaths.length; index++) {
                            that.upImg(res.tempFilePaths[index],'index')
                        }
					}
				});
				// #endif
			},
			upImg:function(url,index){
				this.$show();
				var that = this;
				uni.uploadFile({
					url: 'https://oa.yuxiang123.cn/api/common/upload',
					filePath: url,
					name: 'file',
					success: (uploadFileRes) => {
						that.$hide()
						var data = JSON.parse(uploadFileRes.data);
						if(data.code == 1){
								that.fileList.push(data.data.fullurl)
						}else{
							uni.showToast({
								icon: 'none',
								title: '图片上传失败,换张图试试'
							})
						}
					}
				});
			},
			delImg(index){
				this.fileList.splice(index,1)
			},
		}
	}
</script>
<style lang="scss">
	.active{
		background: #F5CD43 !important;
		font-weight: 600 !important;
		color: #000 !important;
	}
	.category-item{
		background: #f2f2f2;
		color: #333;
		padding: 10rpx 30rpx;
		border-radius: 15rpx;
		font-size: 24rpx;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		display: inline-block;
	}
	//.category{height:80rpx; display: flex;align-items: center;justify-content: space-between;overflow-x: scroll;}
.u-mode-center-box{
	top: -20rpx !important;
}

.top{
	
	align-items: center;
	background-color: #FFFFFF;
	margin: 0 20upx;
	border-radius: 10upx;
	.top_left{
		padding:30upx;
		.sr{
			width: 100%;
			height: 480rpx;
		}
	}
	.top_right{
		padding-right: 20upx;
		height: 260upx;
		width:200upx;
		margin-right: 20upx;
		video{
			position: relative;
			width: 200upx;
			height: 200upx;
			z-index: -1;
		}
		image{
			width:200upx;
			height: 200upx;
			border-radius: 6upx;
		}
		text{
			width:200upx;
			height:60upx;
			line-height: 60upx;
			text-align: center;
			display: block;
			color:red
			}
	}
}
.box{
	border-bottom: 1px solid #f2f2f2;
	height: 110rpx;
	display: flex;
	align-items: center;
	//padding: 20upx 0;
	.box_left{
		min-width:200rpx;
		text{
			margin-left: 10upx;
		}
	}
	
	.box_info_right_radio{
		font-size: 26upx;
	}
	.num{
		input{
			font-size: 26upx;
			color: #999999;
		}
	}
}
.box_text{
	flex: 1;
	text-align: right;
	//color: #999999;
	input{
		font-size:32upx;
		line-height: 60rpx;
		text-align: right;
	}
	.radio{width:40rpx;height:40rpx;float:left;}
	.more{width:40rpx;height:40rpx;float:right;}
	.address{float:right;padding-left:20rpx;}
	.address.xz_1{color:#000;}
	.peisong{float:left;}
	.peisong.xz_1{color:#000;}
}
.center{
	background-color: #FFFFFF;
	border-radius: 10upx;
	padding:0 60upx 0 40upx;
	font-size:32upx;
}
.bomms{
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	flex-grow: 0;
	border-radius: 30rpx;
	flex-basis: auto;
	align-items: stretch;
	align-content: flex-start;width: 100%;height: 400rpx;background: #fff;
}
.fs{
	width: 180rpx;
	height: 55rpx;
	line-height: 55rpx;
	float: right;
	text-align: center;
	margin: 18rpx 25rpx;
	border-radius: 20rpx;
	background-color: #E91E63;
	color: #fff;
}
.bom{
	margin: 20upx;
	background-color: #FFFFFF;
	border-radius: 10upx;
	.bom_title{
		
	}
	.bom_img{
		display: flex;
		flex-wrap: wrap;
		.item{
			text-align: center;
			width: 30%;
			background-color: #f0f0f0;
			height: 200upx;
			border-radius: 10upx;
			margin-top: 20upx;
			color: #999999;
			margin-right: 20upx;
			position: relative;
			.icon{
				position: absolute;
				right: -10upx;
				top: -20upx;
				font-size: 40upx;
				background-color: #FFFFFF;
				border-radius: 50%;
				color: rgba($color: #333, $alpha: 0.5);
			}
			.item_icon{
				margin-top: 40upx;
				font-size: 40upx;
			}
			.item_text{
				color: #999999;
				font-size: 26upx;
				margin-top: 10upx;
			}
			image{
				width: 100%;
				height: 100%;
				border-radius: 10upx;
			}
			.seturl{
				position: absolute;
				bottom: 0;
				width: 100%;
				background-color: rgba($color: #333, $alpha: 0.5);
				border-radius: 0 0 10upx 10upx;
				color: #FFFFFF;
				font-size: 24upx;
				padding: 10upx 0;
			}
			.selectSet{
				background-color: rgba($color: red, $alpha: 0.5);
			}
		}
	}
}
.btn{
	background-color: $uni-color;
	width: 90%;
	margin: auto;
	margin-top: 50upx;
	text-align: center;
	padding: 20upx 0;
	font-size: 28upx;
	border-radius: 50upx;
}

.popup{
	position: fixed;
	top: 40%;
	z-index: 999;
}
.list{
	padding: 0 20upx;
	.list_item{
		padding: 20upx 0;
		.list_item_title{
			font-size: 40upx;
			font-weight: bold;
		}
		.list_item_list{
			display: flex;
			flex-wrap: wrap;
			.item_list_item{
				background-color: #999999;
				color: #FFFFFF;
				padding: 5upx 10upx;
				border-radius: 30upx;
				margin-right: 10upx;
				font-size: 24upx;
				margin-top: 20upx;
			}
		}
	}
}

.popup{
	position: fixed;
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	.popup_box{
		background-color: #FFFFFF;
		width: 90%;
		padding: 30upx 0;
		text-align: center;
		border-radius: 20upx;
		.popup_box_close{
			.close{width:60rpx;height:60rpx;float:right;margin:0 20rpx;}
		}

		.popup_box_title{
			height:60rpx;
			line-height: 60rpx;
		}
		.popup_box_img{
			padding: 30upx 0;
			image{
				width: 200upx;
				height: 200upx;
			}
		}
		.popup_box_text{
			padding: 0 40upx;
		}
	}
}
.blank40{width:100%;height: 80upx;}

.city_change{display:flex;padding:0 30rpx 0 30rpx;flex-direction: column;background-color: #fff;border-radius: 20rpx 20rpx 0 0;height:1000rpx;}

.city_title{display:flex;flex-direction: row;justify-content: space-between; border-radius: 20rpx 20rpx 0 0;margin:20rpx 0;font-size:32rpx;}
.city_title .tit{height:60rpx;line-height:60rpx;font-size:32rpx;}
.city_title .sure{width:80rpx;height:40rpx;margin:10rpx 0 0 0;color:darkorange;}
 
.city_search{display: flex;flex-direction: row;justify-content: space-between;background-color:#f3f3f3;}
.city_search .img{font-size:36rpx;color:#777; margin:20rpx;}
.city_search .search{font-size:28rpx;height:80rpx;line-height:80rpx; text-align: left;flex:1;}

.city_result{display:flex;flex-direction: row;justify-content:flex-start;flex-wrap: wrap;height:900rpx;}
.city_result .result_select{border-bottom: 1px solid #ddd; margin: 10rpx;padding:10rpx;}
.city_result .result_select .result_title{font-size:32rpx;color: #333 !important;height:52rpx;line-height:52rpx;}
.city_result .result_select .result_item{font-size: 26rpx;color:#999;line-height: 40rpx;}

.getcode{font-size:28rpx;background-color: #f0f0f0;border-radius: 10rpx;padding:10rpx 20rpx;}
.dz_box{width:100%;background-color:#fff;border-radius: 10rpx; overflow: hidden;}
.dz_box .dz_close{width:100%;height: 40rpx;
	image{width:50rpx;height: 50rpx;float:right;margin: 20rpx 20rpx 0 0;}
}
.hong{
	width: 20rpx;
    height: 20rpx;
    background: red;
    display: inline-block;
    margin-right: 20rpx;
    border-radius: 50%;
}
.dz_box .dz_title{margin-left: 8%; width:100%;text-align: left; height:80rpx;line-height:80rpx; font-size: 34rpx;color:#000;}
.dz_box .dz_content{width:90%;margin-left: 8%;;line-height:60rpx ; font-size: 32rpx;color:#333;}
.dz_box .dz_btn{
	width:80%;height:100rpx;line-height:100rpx;text-align: center;font-size:36rpx; margin:40rpx 10%;border-radius:50rpx; background-color: #feb543;color:#fff; 
}

.dz_box .dz_btn1{
    line-height: 50rpx;
    text-align: center;
    font-size: 28rpx;
    border-radius: 18rpx;
    background-color: #efebeb;
    color: #000;
    display: table-cell;
    padding: 10rpx 40rpx;
}
.dz_box .dz_btn3{
    line-height: 50rpx;
    text-align: center;
    background-color: #fff;
    color: #fff;
    display: table-cell;
    padding: 6rpx;
}
.dz_box .dz_btn2{
    line-height: 50rpx;
    text-align: center;
    font-size: 28rpx;
    border-radius: 18rpx;
    background-color: #feb543;
    color: #fff;
    display: table-cell;
    padding: 10rpx 40rpx;
}
</style>
